package com.lightsaber.trade.as.service.planning.impl;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lightsaber.trade.as.dao.planning.Level3CampusStatusDao;
import com.lightsaber.trade.as.entity.planning.Level3CampusStatus;
import com.lightsaber.trade.as.service.planning.Level3CampusStatusService;
import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.entity.AuditedObject;
import com.lightsaber.trade.core.entity.BaseEntity;
import com.lightsaber.trade.core.service.BaseServiceImpl;

@Service
@Component
@Transactional
public class Level3CampusStatusServiceImpl extends BaseServiceImpl<Level3CampusStatus, String>
        implements Level3CampusStatusService {

    private static final Logger log = LoggerFactory.getLogger(Level3CampusStatusServiceImpl.class);

    @Autowired
    private Level3CampusStatusDao level3CampusStatusDao;

    @Override
    protected BaseDao<Level3CampusStatus, String> getDao() {
        return level3CampusStatusDao;
    }

    @Override
    public Level3CampusStatus findByLevel3AndCampus(final String level3PlanningId,
            final String discipline, final String campus) {
        return level3CampusStatusDao.findByLevel3AndCampus(level3PlanningId, discipline, campus);

    }

    @Override
    public Level3CampusStatus findById(final String id) {
        return level3CampusStatusDao.findUniqueBy("id", id);

    }

    @Override
    public void save(final Level3CampusStatus level3CampusStatus) {
        if (StringUtils.isBlank(level3CampusStatus.getId())) {
            level3CampusStatusDao.save(level3CampusStatus);
        } else {
            Level3CampusStatus old = findById(level3CampusStatus.getId());
            BeanUtils.copyProperties(level3CampusStatus, old, new String[] { BaseEntity.ID,
                    BaseEntity.VERSION, "level3Planning", AuditedObject.CREATED_BY,
                    AuditedObject.CREATED_DATE });
            level3CampusStatusDao.update(old);
        }

    }

}
